<template>
	<view>
		<view class="card-bg item" v-for="(item,index) in list_data" :key="item" @click="toDetail(item)">
			<view class="left">
				<text class="time">{{formatTime(item)}}</text>
				<text class="name">{{item.visitorName}} {{item.visitorPhone}}</text>
			</view>
			<text class="right">{{getStateName(item)}}</text>
			<image src="../../static/ic_arrow_r.png" class="arrow-r"></image>
		</view>
		<uni-load-more status="loading" v-show="isLoading" />
		<xw-empty v-if="!list_data.length" v-on:refresh="onRefressh"></xw-empty>
	</view>
</template>

<script>
	import cfg from '../../utils/config.js'
	export default {
		data() {
			return {
				list_data: [],
				page: 1,
				isLoading: false
			}
		},
		onPullDownRefresh() {
			this.onRefressh()
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 2000)
		},
		onReachBottom() {
			this.page++;
			this.isLoading = true
			this.getList()
		},
		onLoad() {
			uni.hideHomeButton()
		},
		onShow() {
			this.onRefressh()
		},
		methods: {
			getStateName(item) {
				return cfg.getStateName(item.reachStatus)
			},
			formatTime(item) {
				return cfg.timestampToTime(item.reservationReachTime)
			},
			toDetail(item) {
				uni.navigateTo({
					url: '/pages2/visited/detail?id=' + item.id
				})
			},
			onRefressh() {
				this.page = 1
				this.getList()
			},
			getList() {
				uni.request({
					url: cfg.host + 'cp/reservation/user-page-query',
					method: 'POST',
					data: {
						'pageNo': this.page,
						'isIgnore': 0
					},
					success: (res) => {
						if (res.data.code == 0) {
							let list = res.data.data.list || []
							if (this.page == 1) {
								this.list_data = list
							} else {
								this.list_data = this.list_data.concat(list)
							}
						}
					},
					complete: () => {
						this.isLoading = false
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.item {
		display: flex;
		flex-direction: row;
		align-items: center;

		.left {
			display: flex;
			flex-direction: column;
			flex: 1;

			.time {
				font-size: 32rpx;
			}

			.name {
				margin-top: 20rpx;
			}
		}

		.right {
			font-size: 28rpx;
			margin-right: 10rpx;
			font-size: 26rpx;
		}
	}
</style>